<?php
namespace mobile\controllers;


use frontend\models\ArtForm;
use Yii;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\helpers\Url;
use yii\web\Controller;
use yii\web\Response;
use yii\base\ErrorException;
use yii\helpers\Html;
use common\widgets\file_upload\FileUpload;
use common\models\member\Member;
use common\models\category\Category;
use common\models\articles\Articles;
use common\models\art\Art;
use common\models\meeting\Meeting;
use yii\data\Pagination;
use yii\web\Request;

class HyfabuController extends Controller
{     
	public $layout = 'nomalpage';

	/**
	 * 会员发布内容页
	 */
	public function actionIndex($id){
		$article = Art::find()->where(['status'=>10,'id'=>$id])->asArray()->one();
		$articles = Yii::$app->db->createCommand("select * from art where status = 10 and id != $id LIMIT 5")->queryAll();
		return $this->render('index',[
			'article' =>$article,
			'articles' =>$articles,
		]);
	}


    /**
    * 会员发布列表
    */

  public function actionList(){

	  $articles = Art::find()->where(['status'=>10])->asArray()->limit(9)->all();

	  return $this->render('list',[
			'articles'=>$articles,
	  ]);
  }
  public function actionZenjia(){
	  $num = $_GET['articlecount'];
	  $count = Yii::$app->db->createCommand("SELECT count(*) FROM art WHERE status = 10")
		  ->queryScalar();
	  $articles = Yii::$app->db->createCommand("SELECT * FROM art WHERE status = 10 limit $num,9")
	  ->queryall();
	  foreach ($articles as $key=>$arr){
		  if($count<=($num+9)) {
			  $result[$key] = array(
				  'id' => $arr['id'],
				  'content' => 1,
				  'title' => $arr['title'],
				  'time' => date('Y-m-d H:i:s', $arr['created_at']),
			  );
		  }else{
			  $result[$key] = array(
				  'id' => $arr['id'],
				  'content' => 2,
				  'title' => $arr['title'],
				  'time' => date('Y-m-d H:i:s', $arr['created_at']),
			  );
		  }

	  }
	  echo json_encode($result);

  }



}